import sqlite3
import os
import sys

# 连接到数据库
db_path = os.path.join('db', 'sync.db')
print(f"连接数据库: {db_path}")
print(f"数据库文件是否存在: {os.path.exists(db_path)}")

if not os.path.exists(db_path):
    print("错误: 数据库文件不存在")
    sys.exit(1)

try:
    conn = sqlite3.connect(db_path)
    cursor = conn.cursor()
    
    # 显示清理前的记录
    print("\n清理前的同步目录记录:")
    cursor.execute("SELECT id, user_id, local_path, ftp_host FROM sync_dirs")
    rows = cursor.fetchall()
    for row in rows:
        print(f"ID: {row[0]}, 用户ID: {row[1]}, 本地路径: {row[2]}, FTP主机: {row[3]}")
    
    # 删除ID为11和16的记录
    print("\n删除ID为11和16的记录...")
    cursor.execute("DELETE FROM sync_dirs WHERE id IN (11, 16)")
    cursor.execute("DELETE FROM sync_history WHERE sync_dir_id IN (11, 16)")
    conn.commit()
    print(f"已删除 {cursor.rowcount} 条记录")
    
    # 显示清理后的记录
    print("\n清理后的同步目录记录:")
    cursor.execute("SELECT id, user_id, local_path, ftp_host FROM sync_dirs")
    rows = cursor.fetchall()
    for row in rows:
        print(f"ID: {row[0]}, 用户ID: {row[1]}, 本地路径: {row[2]}, FTP主机: {row[3]}")
    
    conn.close()
    print("\n数据库清理完成")
    
except Exception as e:
    print(f"处理数据库时出错: {e}")

print("\n脚本执行完毕") 